Bite 158. Subclass the list built-in
Login and get codingIn this Bite you will complete
IntList, a subclass oflist, which should be able to do the following:>>> from intlist import IntList >>> mylist = IntList([1, 3, 5]) >>> mylist.mean 3 >>> mylist.median 3 >>> mylist.append(7) >>> mylist.append(1.0) >>> mylist.mean 3.4 >>> mylist.median 3 >>> mylist.append('a') ... TypeError >>> mylist.append([2, 3]) >>> mylist.append([2, 'a']) ... TypeError >>> mylist += [1] >>> mylist += [1, 'a'] ... TypeErrorAs you see this special list is enriched with
meanandmedianproperties, and is restricted tointvalues only, be it as appended individually or aslistofints. Apart from overridingappend, you'll also need to tweak the__add__and__iadd__(operator overloading) dunder methods here.Enjoy and keep calm and code more Python!
Will you be the 155th person to crack this Bite?
Resolution time: ~68 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 6.6 on a 1-10 difficulty scale.
» Up for a challenge? 💪